1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gsk.Renderer; 26 27 private import cairo.Region; 28 private import gdk.Surface; 29 private import gdk.Texture; 30 private import glib.ConstructionException; 31 private import glib.ErrorG; 32 private import glib.GException; 33 private import gobject.ObjectG; 34 private import graphene.Rect; 35 private import gsk.RenderNode; 36 private import gsk.c.functions; 37 public import gsk.c.types; 38 39 40 /** 41 * `GskRenderer` is a class that renders a scene graph defined via a 42 * tree of [class@Gsk.RenderNode] instances. 43 * 44 * Typically you will use a `GskRenderer` instance to repeatedly call 45 * [method@Gsk.Renderer.render] to update the contents of its associated 46 * [class@Gdk.Surface]. 47 * 48 * It is necessary to realize a `GskRenderer` instance using 49 * [method@Gsk.Renderer.realize] before calling [method@Gsk.Renderer.render], 50 * in order to create the appropriate windowing system resources needed 51 * to render the scene. 52 */ 53 public class Renderer : ObjectG 54 { 55 /** the main Gtk struct */ 56 protected GskRenderer* gskRenderer; 57 58 /** Get the main Gtk struct */ 59 public GskRenderer* getRendererStruct(bool transferOwnership = false) 60 { 61 if (transferOwnership) 62 ownedRef = false; 63 return gskRenderer; 64 } 65 66 /** the main Gtk struct as a void* */ 67 protected override void* getStruct() 68 { 69 return cast(void*)gskRenderer; 70 } 71 72 /** 73 * Sets our main struct and passes it to the parent class. 74 */ 75 public this (GskRenderer* gskRenderer, bool ownedRef = false) 76 { 77 this.gskRenderer = gskRenderer; 78 super(cast(GObject*)gskRenderer, ownedRef); 79 } 80 81 82 /** */ 83 public static GType getType() 84 { 85 return gsk_renderer_get_type(); 86 } 87 88 /** 89 * Creates an appropriate `GskRenderer` instance for the given @surface. 90 * 91 * If the `GSK_RENDERER` environment variable is set, GSK will 92 * try that renderer first, before trying the backend-specific 93 * default. The ultimate fallback is the cairo renderer. 94 * 95 * The renderer will be realized before it is returned. 96 * 97 * Params: 98 * surface = a `GdkSurface` 99 * 100 * Returns: a `GskRenderer` 101 * 102 * Throws: ConstructionException GTK+ fails to create the object. 103 */ 104 public this(Surface surface) 105 { 106 auto __p = gsk_renderer_new_for_surface((surface is null) ? null : surface.getSurfaceStruct()); 107 108 if(__p is null) 109 { 110 throw new ConstructionException("null returned by new_for_surface"); 111 } 112 113 this(cast(GskRenderer*) __p, true); 114 } 115 116 /** 117 * Retrieves the `GdkSurface` set using gsk_enderer_realize(). 118 * 119 * If the renderer has not been realized yet, %NULL will be returned. 120 * 121 * Returns: a `GdkSurface` 122 */ 123 public Surface getSurface() 124 { 125 auto __p = gsk_renderer_get_surface(gskRenderer); 126 127 if(__p is null) 128 { 129 return null; 130 } 131 132 return ObjectG.getDObject!(Surface)(cast(GdkSurface*) __p); 133 } 134 135 /** 136 * Checks whether the @renderer is realized or not. 137 * 138 * Returns: %TRUE if the `GskRenderer` was realized, and %FALSE otherwise 139 */ 140 public bool isRealized() 141 { 142 return gsk_renderer_is_realized(gskRenderer) != 0; 143 } 144 145 /** 146 * Creates the resources needed by the @renderer to render the scene 147 * graph. 148 * 149 * Since GTK 4.6, the surface may be `NULL`, which allows using 150 * renderers without having to create a surface. 151 * 152 * Note that it is mandatory to call [method@Gsk.Renderer.unrealize] before 153 * destroying the renderer. 154 * 155 * Params: 156 * surface = the `GdkSurface` renderer will be used on 157 * 158 * Returns: Whether the renderer was successfully realized 159 * 160 * Throws: GException on failure. 161 */ 162 public bool realize(Surface surface) 163 { 164 GError* err = null; 165 166 auto __p = gsk_renderer_realize(gskRenderer, (surface is null) ? null : surface.getSurfaceStruct(), &err) != 0; 167 168 if (err !is null) 169 { 170 throw new GException( new ErrorG(err) ); 171 } 172 173 return __p; 174 } 175 176 /** 177 * Renders the scene graph, described by a tree of `GskRenderNode` instances 178 * to the renderer's surface, ensuring that the given @region gets redrawn. 179 * 180 * If the renderer has no associated surface, this function does nothing. 181 * 182 * Renderers must ensure that changes of the contents given by the @root 183 * node as well as the area given by @region are redrawn. They are however 184 * free to not redraw any pixel outside of @region if they can guarantee that 185 * it didn't change. 186 * 187 * The @renderer will acquire a reference on the `GskRenderNode` tree while 188 * the rendering is in progress. 189 * 190 * Params: 191 * root = a `GskRenderNode` 192 * region = the `cairo_region_t` that must be redrawn or %NULL 193 * for the whole window 194 */ 195 public void render(RenderNode root, Region region) 196 { 197 gsk_renderer_render(gskRenderer, (root is null) ? null : root.getRenderNodeStruct(), (region is null) ? null : region.getRegionStruct()); 198 } 199 200 /** 201 * Renders the scene graph, described by a tree of `GskRenderNode` instances, 202 * to a `GdkTexture`. 203 * 204 * The @renderer will acquire a reference on the `GskRenderNode` tree while 205 * the rendering is in progress. 206 * 207 * If you want to apply any transformations to @root, you should put it into a 208 * transform node and pass that node instead. 209 * 210 * Params: 211 * root = a `GskRenderNode` 212 * viewport = the section to draw or %NULL to use @root's bounds 213 * 214 * Returns: a `GdkTexture` with the rendered contents of @root. 215 */ 216 public Texture renderTexture(RenderNode root, Rect viewport) 217 { 218 auto __p = gsk_renderer_render_texture(gskRenderer, (root is null) ? null : root.getRenderNodeStruct(), (viewport is null) ? null : viewport.getRectStruct()); 219 220 if(__p is null) 221 { 222 return null; 223 } 224 225 return ObjectG.getDObject!(Texture)(cast(GdkTexture*) __p, true); 226 } 227 228 /** 229 * Releases all the resources created by gsk_renderer_realize(). 230 */ 231 public void unrealize() 232 { 233 gsk_renderer_unrealize(gskRenderer); 234 } 235 }